<template>
	<view class="content">
		<view class="head" style="background-color: #FFFFFF;">
			<view v-for="(item,index) in title" :key="index" :class="[index==type?'title_':'title']" @tap="choice(index)">{{item}}</view>
		</view>
		<scroll-view scroll-y>
			<view class="coupon_view" v-for="(item,index) in couponList" :key="index" v-if="type==0">
				<view class="coupon_amount">
					¥
					<view style="font-size: 70upx;font-weight: 800;">
						{{item.amount}}
					</view>
				</view>
				<view style="flex-direction: column;flex: 1;">
					<view style="font-size: 30upx;font-weight: 700;color: #333333">{{item.title}}</view>
					<view style="font-size: 24upx;color: #555555;margin-top: 15upx;">· {{item.amountCondition}}</view>
					<view style="font-size: 24upx;color: #555555;">· {{item.productCondition}}</view>
					<view style="font-size: 24upx;color: #555555;">· {{item.expireTime}}</view>
				</view>
			</view>

			<view class="coupon_view" v-for="(item,index) in couponList" :key="index" v-if="type!=0">
				<view class="coupon_amount_expire">
					¥
					<view style="font-size: 70upx;font-weight: 800;">
						{{item.amount}}
					</view>
				</view>
				<view style="flex-direction: column;flex: 1;">
					<view style="font-size: 30upx;font-weight: 700;color: #888888">{{item.title}}</view>
					<view style="font-size: 24upx;color: #999999;margin-top: 15upx;">· {{item.amountCondition}}</view>
					<view style="font-size: 24upx;color: #999999;">· {{item.productCondition}}</view>
					<view style="font-size: 24upx;color: #999999;">· {{item.expireTime}}</view>
				</view>
				
				<view class="label" v-if="type==1">
					已使用
				</view>
				<view class="label" v-if="type==2">已过期</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import api from '../../common/api.js';
	import {
		getWithParam_
	} from "../../common/request.js"
	export default {
		data() {
			return {
				title: ["未使用", "已使用", "已过期"],
				index: 1,
				pageSize: 10,
				couponList: [],
				type: 0,
				loadMore: true
			}
		},
		onReachBottom() {

		},
		onLoad() {
			this.getData()
		},
		methods: {

			/**
			 * 选择
			 * @param {Object} index
			 */
			choice(index) {
				this.type = index
				this.index = 1
				this.couponList = []
				this.getData()
			},
			/**
			 * 获取数据
			 * 
			 */
			getData() {
				getWithParam_(api.COUPON_USER, {
					type: this.type,
					index: this.index,
					pageSize: this.pageSize
				}).then(res => {
					if (res.data.length < 10) {
						this.loadMore = false
					}
					this.couponList = this.couponList.concat(res.data)
				})
			}
		}
	}
</script>

<style>
	.label{
		background-color: #999999;
		color: #333333;
		font-size: 22upx;
		position: absolute;
		top: -40upx;
		left: -70upx;
		width: 150upx;
		height: 100upx;
		justify-content: center;
		align-items: flex-end;
		transform: rotate(-45deg);
	}
	.coupon_amount_expire{
		color: #888888;
		align-items: flex-end;
		width: 250upx;
		justify-content: center;
	}
	.coupon_view {
		position: relative;
		overflow: hidden;
		background-color: #FFFFFF;
		border-radius: 10upx;
		padding: 30upx 20upx;
		align-items: center;
		margin: 20upx 0;
	}

	.coupon_amount {
		color: #FE0036;
		align-items: flex-end;
		width: 250upx;
		justify-content: center;
	}

	scroll-view {
		height: calc(100vh - 100upx);
		padding: 0upx 30upx 30upx 30upx;
		box-sizing: border-box;
	}

	.head {
		width: 100%;
		height: 100upx;
		justify-content: center;
	}

	.title {
		flex: 1;
		justify-content: center;
		align-items: center;
		color: #555555;
	}

	.title_ {
		flex: 1;
		justify-content: center;
		align-items: center;
		background-color: #FFFFFF;
		color: #FE0036;
		font-size: 32upx;
		font-weight: 600;
	}
</style>
